package com.dean.entity;

import java.util.Map;

/**
 * @ClassName DbConnectInfo
 * @Description 数据库连接信息实体类
 * @Author dean
 * @Date 2021/10/3 7:03
 */
public class SysDbConnInfo {

    private final String CONN_NAME ="CONN_NAME";
    private final String DRIVER="DRIVER";
    private final String URL="URL";
    private final String USERNAME="USERNAME";
    private final String PASSWORD="PASSWORD";
    /**
     * 连接对象名称
     */
    private String connName;
    /**
     * 数据库连接驱动
     */
    private String driver;
    /**
     * 数据库连接url
     */
    private String url;
    /**
     * 数据库用户名
     */
    private String username;
    /**
     * 数据库连接密码
     */
    private String password;

    /**
     * 是否关闭连接 默认是不关闭的
     * @return
     */

    private Boolean close;

    public Boolean getClose() {
        return close==null?false:close;
    }

    public void setClose(Boolean close) {
        this.close = close;
    }

    public String getConnName() {
        return connName;
    }

    public void setConnName(String connName) {
        this.connName = connName;
    }

    public String getDriver() {
        return driver;
    }

    public void setDriver(String driver) {
        this.driver = driver;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void set(String fieldName,Object fieldValue){
        fieldName = fieldName.toUpperCase();
        String value = fieldValue == null ? null : String.valueOf(fieldValue);
        switch (fieldName) {
            case CONN_NAME:
                setConnName(value);
                break;
            case DRIVER:
                setDriver(value);
                break;
            case URL:
                setUrl(value);
                break;
            case USERNAME:
                setUsername(value);
                break;
            case PASSWORD:
                setPassword(value);
                break;
            default:
                break;
        }
    }

    /**
     * 将map转为实体类
     * @param map
     */
    public void set(Map<String,Object> map){
        map.forEach((key,val)->{
            set(key,val);
        });
    }

    @Override
    public String toString() {
        return "DbConnectInfo{" +
                "connName='" + connName + '\'' +
                ", driver='" + driver + '\'' +
                ", url='" + url + '\'' +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}
